<template>
	<view>
		<cu-custom bgColor="bg-while" :isBack="true">
			<block slot="content"></block>
		</cu-custom>
		<view class='pageTeaxview'>
			<view class='Teaview'>
				<textarea placeholder="写点什么分享给大家吧" v-model="form.content" />
			</view>
			<view class="cu-form-group" style="padding: 0;">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in form.imgs" :key="index" @tap="ViewImage" :data-url="form.imgs[index]">
						<image :src="$ComFunJS.ImgFile(item)" mode="aspectFill"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
							<text class='cuIcon-close'></text>
						</view>
					</view>
				</view>
			</view>			
			<view class='flex align-center justify-start'>
				<view class="IconOne flex flex-direction align-center justify-center margin-right-xs" @click="choose">
					<view class="iconfont icon-img"></view>
					<view>图片</view>
				</view>
				<view class="IconOne flex flex-direction align-center justify-center margin-right-xs" @click="chooseVideo">
					<view class="iconfont icon-video"></view>
					<view>视频</view>
				</view>		
				<view class="IconOne flex flex-direction align-center justify-center margin-right-xs" @click="getInfoList">
					<view class="iconfont icon-wenjian"></view>
					<view>文件</view>
				</view>						
			</view>				
		</view>  
		<view class="flex justify-center margin-top padding-bottom" style="margin-top: 500upx;" @click="subMit">
			<button class="add-btn">发布</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				form:{
					content:"",
					videourl:"",
					audiourl:"",
					files:"",
					imgs:[]
				}
			};
		},
		onLoad(option){
			this.id = option.id
		},
		onShow() {
			
		},
		methods: {
			ViewImage(e) {
				uni.previewImage({
					urls: this.form.imgs,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				this.form.imgs.splice(e.currentTarget.dataset.index, 1)
			},			
			getInfoList(){
				let chooseImg = this.$ComFunJS.ChooseVideo();
				chooseImg.then((res)=>{
					console.log(res)
					if(res.length){
						this.form.cover=res[0]					
					}
				})
			},
			//视频上传
			chooseVideo(){
				let chooseImg = this.$ComFunJS.ChooseVideo();
				chooseImg.then((res)=>{
					console.log(res)
					if(res.length){
						this.form.cover=res[0]					
					}
				})
			},				
			// 图片上传
			choose(){
				let chooseImg = this.$ComFunJS.ChooseImage(5);
				chooseImg.then((res)=>{
					if(res.length){
						this.form.imgs= [...this.form.imgs,...res]				
					}
				})
			},	
			subMit(){
				let data = {...this.form}
				if(!data.content){
					this.$api.msg('内容不能为空');
					return
				}
				if(data.imgs.length){
					data.imgs = data.imgs.join(',')
				}else{
					data.imgs = ""
				}
				data.xid = this.id;
				this.$ComFunJS.ajax({
					url:'/addons/cms/api/htadd',
					method: 'post',
					data:{
						...data
					},
					success: (res) => {
						if (res.code==1) {
							this.$api.msg('添加成功');
							uni.navigateBack({ delta: 1 });
						} else {
							this.$api.msg(res.data.error);
							
						}
					}
				})	
			},
		},

	}
</script>

<style  lang="scss">
page{
  background: #fff
}
.pageTeaxview{
  padding:0 30upx;
}
.textareaView{
	height: 500upx;
}
.IconOne{
	width:160upx;
	height: 160upx;
	color: #9B9B9B;
	background: #F6F6F6;
	.iconfont{
		font-size: 60upx;
	}
}
</style>
